#!/bin/sh
#-
# Copyright (c) 2010 iXsystems, Inc., All rights reserved.
#   Written by:	Xin LI
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL Jordan Hubbard OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

. /etc/rc.subr


#
#	FreeNAS settings	
#
: ${FREENAS_CONFIG:="/data/freenas-v1.db"}
: ${FREENAS_SQLITE_CMD:="/usr/local/bin/sqlite3fn"}
: ${FREENAS_VERSIONFILE:="/etc/version"}

#
#	Updater specific variables.
#
: ${CD_UPGRADE_SENTINEL="/data/cd-upgrade"}
: ${NEED_UPDATE_SENTINEL="/data/need-update"}


#
#	LDAP settings
#
: ${LDAP_CONF:="/usr/local/etc/openldap/ldap.conf"}

#
#	NSS settings
#
: ${PATH_NS_CONF:="/etc/nsswitch.conf"}

#
#	Kerberos settings
#
: ${PATH_KRB5_CONFIG:="/etc/krb5.conf"}

#
#	Samba settings
#
: ${SAMBA_CONF:="/usr/local/etc/smb4.conf"}
: ${SAMBA_SHARE_CONF:="/usr/local/etc/smb4_share.conf"}



#
#	General purpose utility functions.
#


is_freenas()
{

	if cat ${FREENAS_VERSIONFILE} | grep -qi ^freenas
	then
		return 0
	else
		return 1
	fi

}


ro_sqlite()
{
	local name ret
	name=$1
	ret=$(mktemp /tmp/${name}.XXXXX 2> /tmp/${name}.rcfail && rm /tmp/${name}.rcfail)
	cp ${FREENAS_CONFIG} ${ret}
	echo ${ret}
}
